package com.webClient;

import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.client.ClientResponse;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;

public class GreetingWebClient {
    /**
     * For reactive applications, Spring offers the WebClient class, which is non-blocking.
     * <p>
     * WebClient can be used to communicate with non-reactive, blocking services, too.
     */
    private WebClient client = WebClient.create("http://localhost:8080");

    private Mono<ClientResponse> result = client.post()
            .uri("/hello")
            .accept(MediaType.TEXT_PLAIN)
            .exchange();

    public String getResult() {
        return ">> result = " + result.flatMap(res -> res.bodyToMono(String.class)).block();
    }
}
